Option Strict Off
Option Explicit On

Public Class Parametro
    Private m_Items As Parametros

    Private m_CodigoOperacionU As Integer
    Private m_CodigoOperacion As Integer
    Private m_CodigoProceso As Integer
    Private m_CodigoServicio As Integer
    Private m_TipoIO As Short
    Private m_CodigoSeccion As Integer
    Private m_Index As Short
    Private m_CodigoParametro As Integer
    Private m_FKParametro As String

    Private m_Nombre As String
    Private m_Descripcion As String
    Private m_TipoDato As Short
    Private m_Largo As Short
    Private m_Decimales As Short
    Private m_Formato As String
    Private m_Delimitador As String
    Private m_Orden As Short
    Private m_CodigoSeccionRel As Integer

    Private m_Origen As Short
    Private m_Valor As String

    Private m_TipoValidacion As Short
    Private m_CodRelVal As String

    Private m_OrigenU As Short
    Private m_ValorU As String
    Private m_ReglaValor As Short

    Private m_Excluir As Boolean

    Private m_Relativo As Short
    Private m_ParametroRelativo As String
    Private m_CondicionRelativo As String
    Private m_ValorRelativo As Object

    Public Property CodRelVal() As String
        Get
            Return m_CodRelVal
        End Get
        Set(ByVal Value As String)
            m_CodRelVal = Value
        End Set
    End Property

    Public Property CodigoOperacionU() As Integer
        Get
            Return m_CodigoOperacionU
        End Get
        Set(ByVal Value As Integer)
            m_CodigoOperacionU = Value
        End Set
    End Property

    Public Property CodigoOperacion() As Integer
        Get
            Return m_CodigoOperacion
        End Get
        Set(ByVal Value As Integer)
            m_CodigoOperacion = Value
        End Set
    End Property

    Public Property CodigoProceso() As Integer
        Get
            Return m_CodigoProceso
        End Get
        Set(ByVal Value As Integer)
            m_CodigoProceso = Value
        End Set
    End Property

    Public Property CodigoServicio() As Integer
        Get
            Return m_CodigoServicio
        End Get
        Set(ByVal Value As Integer)
            m_CodigoServicio = Value
        End Set
    End Property

    Public Property TipoIO() As Integer
        Get
            Return m_TipoIO
        End Get
        Set(ByVal Value As Integer)
            m_TipoIO = Value
        End Set
    End Property

    Public Property CodigoSeccion() As Integer
        Get
            Return m_CodigoSeccion
        End Get
        Set(ByVal Value As Integer)
            m_CodigoSeccion = Value
        End Set
    End Property

    Public Property Index() As Short
        Get
            Return m_Index
        End Get
        Set(ByVal Value As Short)
            m_Index = Value
        End Set
    End Property

    Public Property CodigoParametro() As Integer
        Get
            Return m_CodigoParametro
        End Get
        Set(ByVal Value As Integer)
            m_CodigoParametro = Value
        End Set
    End Property

    Public Property FKParametro() As String
        Get
            Return m_FKParametro
        End Get
        Set(ByVal Value As String)
            m_FKParametro = Value
        End Set
    End Property

    Public Property Orden() As Short
        Get
            Return m_Orden
        End Get
        Set(ByVal Value As Short)
            m_Orden = Value
        End Set
    End Property

    Public Property TipoValidacion() As Short
        Get
            Return m_TipoValidacion
        End Get
        Set(ByVal Value As Short)
            m_TipoValidacion = Value
        End Set
    End Property

    Public Property Nombre() As String
        Get
            Return m_Nombre
        End Get
        Set(ByVal Value As String)
            m_Nombre = Value
        End Set
    End Property

    Public Property Descripcion() As String
        Get
            Return m_Descripcion
        End Get
        Set(ByVal Value As String)
            m_Descripcion = Value
        End Set
    End Property

    Public Property TipoDato() As Short
        Get
            Return m_TipoDato
        End Get
        Set(ByVal Value As Short)
            m_TipoDato = Value
        End Set
    End Property

    Public Property Largo() As Short
        Get
            Return m_Largo
        End Get
        Set(ByVal Value As Short)
            m_Largo = Value
        End Set
    End Property

    Public Property Decimales() As Short
        Get
            Return m_Decimales
        End Get
        Set(ByVal Value As Short)
            m_Decimales = Value
        End Set
    End Property

    Public Property Formato() As String
        Get
            Return m_Formato
        End Get
        Set(ByVal Value As String)
            m_Formato = Value
        End Set
    End Property

    Public Property Delimitador() As String
        Get
            Return m_Delimitador
        End Get
        Set(ByVal Value As String)
            m_Delimitador = Value
        End Set
    End Property

    Public Property CodigoSeccionRel() As Integer
        Get
            Return m_CodigoSeccionRel
        End Get
        Set(ByVal Value As Integer)
            m_CodigoSeccionRel = Value
        End Set
    End Property

    Public Property Origen() As Short
        Get
            Return m_Origen
        End Get
        Set(ByVal Value As Short)
            m_Origen = Value
        End Set
    End Property

    Public Property Valor() As String
        Get
            Return m_Valor
        End Get
        Set(ByVal Value As String)
            If Not IsDBNull(Value) Then
                m_Valor = Value
            Else
                m_Valor = ""
            End If
        End Set
    End Property

    Public Property OrigenU() As Short
        Get
            Return m_OrigenU
        End Get
        Set(ByVal Value As Short)
            m_OrigenU = Value
        End Set
    End Property

    Public Property ValorU() As String
        Get
            Return m_ValorU
        End Get
        Set(ByVal Value As String)
            If Not IsDBNull(Value) Then
                m_ValorU = Value
            Else
                m_ValorU = ""
            End If
        End Set
    End Property

    Public Property ReglaValor() As Short
        Get
            Return m_ReglaValor
        End Get
        Set(ByVal Value As Short)
            m_ReglaValor = Value
        End Set
    End Property

    Public Property Excluir() As Boolean
        Get
            Return m_Excluir
        End Get
        Set(ByVal Value As Boolean)
            m_Excluir = Value
        End Set
    End Property

    Public Property Relativo() As String
        Get
            Return CStr(m_Relativo)
        End Get
        Set(ByVal Value As String)
            m_Relativo = CShort(Value)
        End Set
    End Property

    Public Property ParametroRelativo() As String
        Get
            Return m_ParametroRelativo
        End Get
        Set(ByVal Value As String)
            m_ParametroRelativo = Value
        End Set
    End Property

    Public Property CondicionRelativo() As String
        Get
            Return m_CondicionRelativo
        End Get
        Set(ByVal Value As String)
            m_CondicionRelativo = Value
        End Set
    End Property

    Public Property ValorRelativo() As Object
        Get
            Return m_ValorRelativo
        End Get
        Set(ByVal Value As Object)
            m_ValorRelativo = Value
        End Set
    End Property

    Public Property Items() As Parametros
        Get
            Return m_Items
        End Get
        Set(ByVal Value As Parametros)
            m_Items = Value
        End Set
    End Property

    Public Function Clone() As Parametro
        Dim Copia As Parametro

        Copia = New Parametro

        With Copia
            .CodigoOperacionU = m_CodigoOperacionU
            .CodigoOperacion = m_CodigoOperacion
            .CodigoProceso = m_CodigoProceso
            .CodigoServicio = m_CodigoServicio
            .TipoIO = m_TipoIO
            .CodigoSeccion = m_CodigoSeccion
            .Index = m_Index
            .CodigoParametro = m_CodigoParametro
            .FKParametro = m_FKParametro

            .Nombre = m_Nombre
            .Descripcion = m_Descripcion
            .TipoDato = m_TipoDato
            .Largo = m_Largo
            .Decimales = m_Decimales
            .Formato = m_Formato
            .Delimitador = m_Delimitador
            .CodigoSeccionRel = m_CodigoSeccionRel

            .Origen = m_Origen
            .Valor = m_Valor

            .OrigenU = m_OrigenU
            .ValorU = m_ValorU
            .ReglaValor = m_ReglaValor

            .Excluir = m_Excluir

            If m_TipoDato = Declaraciones.TypeDataParameterEnum.TypeDataParameterComposed Or m_TipoDato = Declaraciones.TypeDataParameterEnum.TypeDataParameterOcurrence Then
                If Not m_Items Is Nothing Then
                    .Items = m_Items.Clone
                End If
            End If

        End With

        Return Copia
    End Function

    Public Overrides Function toString() As String
        Dim cadena As String
        Dim pos As Short

        cadena = Trim(m_Valor)

        Select Case m_TipoDato
            Case Declaraciones.TypeDataParameterEnum.TypeDataParameterComposed, Declaraciones.TypeDataParameterEnum.TypeDataParameterOcurrence
                If Not m_Items Is Nothing Then
                    cadena = m_Items.toString()

                    If Len(cadena) > 0 Then
                        If Len(cadena) < m_Largo And m_Largo > 0 Then
                            cadena = cadena & Space(m_Largo - Len(cadena))
                        ElseIf Len(cadena) > m_Largo And m_Largo > 0 Then
                            cadena = Mid(cadena, 1, m_Largo)
                        End If
                    Else
                        cadena = ""
                    End If
                End If
            Case Declaraciones.TypeDataParameterEnum.TypeDataParameterNumeric
                If cadena <> "" Then
                    If Not IsNumeric(cadena) Then
                        cadena = "0"
                    End If

                    If Trim(m_Formato) = "" And m_Largo > 0 Then
                        m_Formato = RepeatChar("0", m_Largo)
                    End If

                    If m_Formato <> "" Then
                        cadena = VB6.Format(cadena, m_Formato)
                        pos = InStr(cadena, ",")
                        If pos > 0 Then
                            cadena = Replace(cadena, ",", ".")
                        End If

                    End If

                    If Len(cadena) > m_Largo And m_Largo > 0 Then
                        cadena = Mid(cadena, 1, m_Largo)
                    ElseIf Len(cadena) < m_Largo And m_Largo > 0 Then
                        cadena = cadena & Space(m_Largo - Len(cadena))
                    End If
                Else
                    cadena = RepeatChar(" ", m_Largo)
                End If
            Case Declaraciones.TypeDataParameterEnum.TypeDataParameterText
                If cadena <> "" Then
                    If Len(cadena) > m_Largo And m_Largo > 0 Then
                        cadena = Mid(cadena, 1, m_Largo)
                    ElseIf Len(cadena) < m_Largo And m_Largo > 0 Then
                        cadena = cadena & Space(m_Largo - Len(cadena))
                    End If
                Else
                    cadena = RepeatChar(" ", m_Largo)
                End If
            Case Declaraciones.TypeDataParameterEnum.TypeDataParameterDateTime
                If cadena <> "" Then
                    If (Len(m_Formato) > 0) Then
                        If (Trim(m_Formato) = "mm/dd/yyyy") Then
                            cadena = Mid(cadena, 4, 2) & "/" & Mid(cadena, 1, 2) & "/" & Mid(cadena, 7, 4)
                        End If
                        'Else
                        '    .Valor = Format(cadena, UCase(Trim(m_Formato)))
                    End If

                    If Len(cadena) > m_Largo And m_Largo > 0 Then
                        cadena = Mid(cadena, 1, m_Largo)
                    ElseIf Len(cadena) < m_Largo And m_Largo > 0 Then
                        cadena = cadena & Space(m_Largo - Len(cadena))
                    End If
                Else
                    cadena = RepeatChar(" ", m_Largo)
                End If
            Case Declaraciones.TypeDataParameterEnum.TypeDataParameterNumericSRM
                If cadena <> "" Then
                    If Trim(m_Formato) <> "" Then
                        cadena = FormatNumeroSrm(cadena, m_Formato)
                    End If

                    If Len(cadena) > m_Largo And m_Largo > 0 Then
                        cadena = Mid(cadena, 1, m_Largo)
                    ElseIf Len(cadena) < m_Largo And m_Largo > 0 Then
                        cadena = cadena & Space(m_Largo - Len(cadena))
                    End If
                Else
                    cadena = RepeatChar(" ", m_Largo)
                End If
        End Select

        Return cadena
    End Function

    Public Function hasChildren() As Boolean
        hasChildren = False
        If m_TipoDato = Declaraciones.TypeDataParameterEnum.TypeDataParameterComposed Or m_TipoDato = Declaraciones.TypeDataParameterEnum.TypeDataParameterOcurrence Then
            hasChildren = True
        End If
    End Function

    Public Function Key() As String
        Key = m_CodigoServicio & "." & m_TipoIO & "." & m_CodigoSeccion & "." & m_CodigoParametro & "[" & m_Index & "]" & "@" & m_FKParametro
    End Function

    Protected Overrides Sub Finalize()
        m_Items = Nothing

        MyBase.Finalize()
    End Sub
End Class